Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: Switch to ST124 "shorthand notation" syntax in charmcraft.yaml #258

Merged
merged 12 commits into from
Jan 10, 2025

Conversation

carlcsaposs-canonical
Copy link
Contributor

Enables building & releasing multi-base charms with 24.04 in a single charmcraft.yaml and git branch

Integration testing is not supported on multiple bases—it is currently only supported on 22.04

Breaking changes

  • ST124 "shorthand notation" syntax required in charmcraft.yaml
  • pytest-operator-cache (which overrides ops_test.build_charm from pytest-operator) now assumes 22.04 base

Deprecation notice

  • pytest-operator-cache is deprecated & will be removed in a future release

@carlcsaposs-canonical
Copy link
Contributor Author

Will not be merged until coordinated charmcraft 3 migration (https://chat.canonical.com/canonical/pl/wekd7r4eqtdn7mxhgxgej8zzsr)

Depends on #258

Comment on lines 9 to 10
# TODO: use permalink
warnings.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will address right before merging (when version number for permalink can be predicted)

@carlcsaposs-canonical carlcsaposs-canonical changed the title breaking: Support ST124 shorthand notation syntax in charmcraft.yaml breaking: Switch to ST124 "shorthand notation" syntax in charmcraft.yaml Dec 19, 2024
Comment on lines +62 to +69
if not isinstance(platforms_, dict):
raise TypeError("Expected type 'dict' for snapcraft.yaml 'platforms'")
for value in platforms_.values():
if value is not None:
raise ValueError(
"Only shorthand notation supported in snapcraft.yaml 'platforms'. "
"'build-on' and 'build-for' not supported"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't help but think that this is a validation snippet, which could be extracted to a helper function to reduce the cognitive load of parsing this whole collect function. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think adding a layer of abstraction would improve readability

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not call replacing a snippet by a function call adding an abstraction layer. Just in case I did not explain myself well enough, this is what I am proposing:

Before
if yaml_data["base"] == "core24":
  platforms_ = yaml_data["platforms"]
  if not isinstance(platforms_, dict):
    raise TypeError("Expected type 'dict' for snapcraft.yaml 'platforms'")
  for value in platforms_.values():
    if value is not None:
      raise ValueError(
        "Only shorthand notation supported in snapcraft.yaml 'platforms'. "
        "'build-on' and 'build-for' not supported"
      )
  for platform in platforms_:
    # Example `platform`: "amd64"
    architecture = craft.Architecture(platform)
    platforms.append({"name": platform, "runner": RUNNERS[architecture]})
elif yaml_data["base"] == "core22":
  for entry in yaml_data["architectures"]:
    # Example: "amd64"
    platform = entry["build-on"]
    architecture = craft.Architecture(platform)
    platforms.append({"name": platform, "runner": RUNNERS[architecture]})
After
if yaml_data["base"] == "core24":
  validate_snap_platforms(yaml_data["platforms"])  # However you want to call it
  for platform in yaml_data["platforms"]:
    # Example `platform`: "amd64"
    architecture = craft.Architecture(platform)
    platforms.append({"name": platform, "runner": RUNNERS[architecture]})
elif yaml_data["base"] == "core22":
  for entry in yaml_data["architectures"]:
    # Example: "amd64"
    platform = entry["build-on"]
    architecture = craft.Architecture(platform)
    platforms.append({"name": platform, "runner": RUNNERS[architecture]})

Base automatically changed from charmcraft-3 to main January 10, 2025 10:00
@carlcsaposs-canonical carlcsaposs-canonical marked this pull request as ready for review January 10, 2025 10:05
@carlcsaposs-canonical carlcsaposs-canonical merged commit 92d0a9f into main Jan 10, 2025
1 check passed
@carlcsaposs-canonical carlcsaposs-canonical deleted the charmcraftst124 branch January 10, 2025 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants